# 夜魅小说网 数据入库
import pymysql
def insert_novel_mysql(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number):
    conn = pymysql.Connect(
        host='',  ##mysql服务器地址
        port=3306,  ##mysql服务器端口号
        user='root',  ##用户名
        password='nx123',  ##密码
        db='nx_spider_novel',  ##数据库名
        charset='utf8'  ##连接编码
    )
    cursor = conn.cursor()
    sql_insert = "INSERT INTO yemei_spider_novel(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')".format(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number)
    # 执行语句
    cursor.execute(sql_insert)
    #事务提交，否则数据库得不到更新
    conn.commit()
    cursor.close()
    conn.close()

def select_novel_mysql(url):
    conn = pymysql.Connect(
        host='',  ##mysql服务器地址
        port=3306,  ##mysql服务器端口号
        user='root',  ##用户名
        password='nx123',  ##密码
        db='nx_spider_novel',  ##数据库名
        charset='utf8'  ##连接编码
    )
    cursor = conn.cursor()
    sql_select = "SELECT * FROM yemei_spider_novel WHERE url ='{0}'".format(url)
    effect_row = cursor.execute(sql_select)
    conn.commit()
    cursor.close()
    conn.close()
    # print('effect_row=''{0}'.format(effect_row))
    return effect_row
def Update_novel_mysql(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number):
    conn = pymysql.Connect(
        host='',  ##mysql服务器地址
        port=3306,  ##mysql服务器端口号
        user='root',  ##用户名
        password='nx123',  ##密码
        db='nx_spider_novel',  ##数据库名
        charset='utf8'  ##连接编码
    )
    cursor = conn.cursor()
    sql_update = "UPDATE yemei_spider_novel SET Public_platform='{0}',Creation_time='{2}',Novel_name='{3}',Number_clicks='{4}',New_reading_users='{5}',New_attention='{6}',Recharge_amount='{7}',Recharge_number='{8}' WHERE url = '{1}'".format(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number)
    cursor.execute(sql_update)
    conn.commit()
    cursor.close()
    conn.close()

#流浪小说 数据入库
def liulang_insert_novel_mysql(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number):
    conn = pymysql.Connect(
        host='',  ##mysql服务器地址
        port=3306,  ##mysql服务器端口号
        user='root',  ##用户名
        password='nx123',  ##密码
        db='nx_spider_novel',  ##数据库名
        charset='utf8'  ##连接编码
    )
    cursor = conn.cursor()
    sql_insert = "INSERT INTO liulang_spider_novel(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')".format(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number)
    # 执行语句
    cursor.execute(sql_insert)
    #事务提交，否则数据库得不到更新
    conn.commit()
    cursor.close()
    conn.close()

def liulang_select_novel_mysql(url):
    conn = pymysql.Connect(
        host='',  ##mysql服务器地址
        port=3306,  ##mysql服务器端口号
        user='root',  ##用户名
        password='nx123',  ##密码
        db='nx_spider_novel',  ##数据库名
        charset='utf8'  ##连接编码
    )
    cursor = conn.cursor()
    sql_select = "SELECT * FROM liulang_spider_novel WHERE url ='{0}'".format(url)
    effect_row = cursor.execute(sql_select)
    conn.commit()
    cursor.close()
    conn.close()
    # print('effect_row=''{0}'.format(effect_row))
    return effect_row

def liulang_Update_novel_mysql(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number):
    conn = pymysql.Connect(
        host='',  ##mysql服务器地址
        port=3306,  ##mysql服务器端口号
        user='root',  ##用户名
        password='nx123',  ##密码
        db='nx_spider_novel',  ##数据库名
        charset='utf8'  ##连接编码
    )
    cursor = conn.cursor()
    sql_update = "UPDATE liulang_spider_novel SET Public_platform='{0}',Creation_time='{2}',Novel_name='{3}',Number_clicks='{4}',New_reading_users='{5}',New_attention='{6}',Recharge_amount='{7}',Recharge_number='{8}' WHERE url = '{1}'".format(Public_platform,url,Creation_time,Novel_name,Number_clicks,New_reading_users,New_attention,Recharge_amount,Recharge_number)
    cursor.execute(sql_update)
    conn.commit()
    cursor.close()
    conn.close()

def zhangzhongyun_spider_everyday_sum(date_time,General_recharge,Platform):
    conn = pymysql.Connect(
        host='',  ##mysql服务器地址
        port=3306,  ##mysql服务器端口号
        user='root',  ##用户名
        password='nx123',  ##密码
        db='nx_spider_everyday_sum',  ##数据库名
        charset='utf8'  ##连接编码
    )
    cursor = conn.cursor()

    sql_insert = "INSERT INTO zhangzhongyun_spider_everyday_sum(date_time,General_recharge,Platform) values('{0}','{1}','{2}')".format(date_time,General_recharge,Platform)
    # 执行语句
    cursor.execute(sql_insert)
    # 事务提交，否则数据库得不到更新
    conn.commit()
    cursor.close()
    conn.close()

